/**
 * Copyright &copy; 2015-2020 <a href="http://www.easyhis.com/">easyhis</a> All rights reserved.
 */
package com.easy.dfcapi.entity;

import com.easy.common.utils.IdGen;
import com.easy.modules.sys.entity.User;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonBackReference;
import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;

import com.easy.core.persistence.DataEntity;
import com.easy.common.utils.excel.annotation.ExcelField;

/**
 * 购物车Entity
 * @author waylen chi
 * @version 2018-01-17
 */
public class ApiCart extends DataEntity<ApiCart> {
	
	private static final long serialVersionUID = 1L;
	private Integer cartId;		// cart_id
	private String id;		// UUID
	private User user;		// 用户ID
	private String sessionId;		// 如果该用户退出,该Session_id对应的购物车中所有记录都将被删除
	private Integer productId;		// 商品ID
	private Integer colorId;		// 商品的颜色ID
	private Integer sizeId;		// 商品的尺寸ID
	private ApiCart parent;		// 该商品的父商品ID,没有该值为0,有的话那该商品就是该id的配件
	private Integer num;		// 商品的购买数量,在购物车时,实际库存不减少
	private BigDecimal price;		// 商品的本店价(加入购物车时)
	private String attrs;		// 商品的扩展属性
	private Integer cartType;		// 购物车商品类型;0普通;1团够;2拍卖;.....
	private String isGift;		// 是否赠品,0否;其他, 是参加优惠活动的id
	private Date createTime;		// 创建时间
	private Date updateTime;		// 最后更新时间
	
	public ApiCart() {
		super();
	}

	public ApiCart(String id){
		this.id = id;
	}

	@ExcelField(title="cart_id", align=2, sort=0)
	public Integer getCartId() {
		return cartId;
	}

	public void setCartId(Integer cartId) {
		this.cartId = cartId;
	}
	
	@ExcelField(title="UUID", align=2, sort=1)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	@NotNull(message="用户ID不能为空")
	@ExcelField(title="用户ID", fieldType=User.class, value=".userName", align=2, sort=2)
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	@ExcelField(title="如果该用户退出,该Session_id对应的购物车中所有记录都将被删除", align=2, sort=3)
	public String getSessionId() {
		return sessionId;
	}

	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}
	
	@NotNull(message="商品ID不能为空")
	@ExcelField(title="商品ID", align=2, sort=4)
	public Integer getProductId() {
		return productId;
	}

	public void setProductId(Integer productId) {
		this.productId = productId;
	}
	
	@ExcelField(title="商品的颜色ID", align=2, sort=5)
	public Integer getColorId() {
		return colorId;
	}

	public void setColorId(Integer colorId) {
		this.colorId = colorId;
	}
	
	@ExcelField(title="商品的尺寸ID", align=2, sort=6)
	public Integer getSizeId() {
		return sizeId;
	}

	public void setSizeId(Integer sizeId) {
		this.sizeId = sizeId;
	}
	
	@JsonBackReference
	@ExcelField(title="该商品的父商品ID,没有该值为0,有的话那该商品就是该id的配件", fieldType=ApiCart.class, value="parent.name", align=2, sort=7)
	public ApiCart getParent() {
		return parent;
	}

	public void setParent(ApiCart parent) {
		this.parent = parent;
	}
	
	@ExcelField(title="商品的购买数量,在购物车时,实际库存不减少", align=2, sort=8)
	public Integer getNum() {
		return num;
	}

	public void setNum(Integer num) {
		this.num = num;
	}
	
	@ExcelField(title="商品的本店价(加入购物车时)", align=2, sort=9)
	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}
	
	@ExcelField(title="商品的扩展属性", align=2, sort=10)
	public String getAttrs() {
		return attrs;
	}

	public void setAttrs(String attrs) {
		this.attrs = attrs;
	}
	
	@ExcelField(title="购物车商品类型;0普通;1团够;2拍卖;.....", align=2, sort=11)
	public Integer getCartType() {
		return cartType;
	}

	public void setCartType(Integer cartType) {
		this.cartType = cartType;
	}
	
	@ExcelField(title="是否赠品,0否;其他, 是参加优惠活动的id", align=2, sort=12)
	public String getIsGift() {
		return isGift;
	}

	public void setIsGift(String isGift) {
		this.isGift = isGift;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@NotNull(message="创建时间不能为空")
	@ExcelField(title="创建时间", align=2, sort=13)
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@ExcelField(title="最后更新时间", align=2, sort=14)
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	/**
	 * 插入之前执行方法，需要手动调用
	 */
	public void preInsert(){
		this.id = IdGen.uuid();

		this.updateTime = new Date();
		this.createTime = this.updateTime;
	}

	/**
	 * 更新之前执行方法，需要手动调用
	 */
	public void preUpdate(){
		this.updateTime = new Date();
	}
	/**
	 * 插入之前执行方法，需要手动调用
	 */
	public void preInsert(Date now){
		this.id = IdGen.uuid();

		this.updateTime = now;
		this.createTime = this.updateTime;
	}

	/**
	 * 更新之前执行方法，需要手动调用
	 */
	public void preUpdate(Date now){
		this.updateTime = now;
	}


}